Ext.define('Fxt.gt-jy.Controller', {
    extend: 'Fxt.core.CrudController',
    stores: 'Fxt.gt-jy.Store',
    models: ['Fxt.gt-jy.Model'],
    views: ['Fxt.gt-jy.view.Viewport', 'Fxt.gt-jy.view.Grid', 'Fxt.gt-jy.view.QueryForm'],
    $onInit: function() {
        var me = this;
        var queryForm = me.$getViewport().$getQueryForm();
        var grid = me.$getViewport().$getGrid();
        var module = me.$getModule();
        this.control({
            'button[action=new-my-jy]': {
                click: function(btn) {
                    Fxt.requireWithLoading(module + '.view.NewJyForm', function() {
                        var form = Ext.create(module + '.view.NewJyForm');
                        var win = Ext.create('Fxt.core.view.Window', {
                            title: '创建新的交易',
                            items: [form],
                            buttons: [{
                                text: '确定',
                                handler: function() {
                                    form.getForm().submit({
                                        url: '/gt/new-my-jy',
                                        waitMsg: '正在新的交易',
                                        success: function() {
                                            win.close();
                                            Fxt.success('创建成功');
                                            me.$doQuery();
                                        },
                                        failure: Fxt._defaultSubmitFailure
                                    });
                                }
                            }]
                        });
                    });
                }
            },
            'button[action=new-sys-jy]': {
                click: function(btn) {
                    Fxt.ajax({
                        method: 'POST',
                        url: '/gt/new-sys-jy',
                        success: function (data) {
                            Fxt.success('新增交易成功');
                            me.$doQuery();
                        }
                    });
                }
            },
            'button[action=sync-my-account]': {
                click: function(btn) {
                    Fxt.ajax({
                        method: 'POST',
                        url: '/gt/sync-my-account',
                        success: function (data) {
                            Fxt.success('同步成功');
                        }
                    });
                }
            }
        });
    }
});